package com.zxt.controller.common;

import com.zxt.security.bean.LoginUser;
import com.zxt.security.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author zxt
 */
public class CommonController {
    private static final Logger log = LoggerFactory.getLogger(CommonController.class);

    public CommonController() {
    }

    public HttpServletRequest getRequest() {
        return RequestContextHolder.currentRequestAttributes() == null ? null : ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
    }

    public HttpServletResponse getResponse() {
        return RequestContextHolder.getRequestAttributes() == null ? null : ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
    }

    public HttpSession getSession() {
        HttpServletRequest request = this.getRequest();
        HttpSession session = request == null ? null : request.getSession();
        return session;
    }

    protected LoginUser getUser() {
        return SecurityUtils.getLoginUser();
    }
}
